import $url from "./url"
import $helper from "./helper"

export { tenantId, baseUrl, fileUrl } from "./global"


export const udp = {
  $url,
  $helper
}

export const navigateTo = (url, params) => {
  if (params) {
    url = `?${paramsToQuery(params)}` 
  }
  uni.navigateTo({ url })
}

export const navigateBack = (delta = 1 ) => {
  uni.navigateBack({ delta })
}

export const successTotast = (title) => {
  uni.showToast({
    title,
    icon: 'success',
    mask: true
  })
}

export const errorTotast = (title) => {
  uni.showToast({
    title,
    icon: 'error',
    mask: true
  })
}

function paramsToQuery(params) {
  if (isEmpty(params)) {
    return '';
  }
  // return new URLSearchParams(Object.entries(params)).toString();
  let query = [];
  for (let key in params) {
    query.push(key + '=' + params[key]);
  }

  return query.join('&');
}